import wtforms
from flask_wtf import FlaskForm
from wtforms.validators import Email, DataRequired, Length, EqualTo


class UserRegisterForm(FlaskForm):
    """用户注册表单"""
    username = wtforms.StringField('用户名', validators=[DataRequired()], render_kw={'placeholder': '5-20位字母、数字或下划线'})
    password = wtforms.PasswordField('密码',
                                     validators=[DataRequired(), EqualTo('password2', message='两次输入的密码不一致')])
    password2 = wtforms.PasswordField('确认密码', validators=[DataRequired()])
    email = wtforms.StringField('邮箱', validators=[DataRequired(), Length(1, 64), Email(message='邮箱格式不正确')])
    submit = wtforms.SubmitField('提交注册')


class UserLoginForm(FlaskForm):
    """用户登录表单"""
    username = wtforms.StringField('用户名', validators=[DataRequired()])
    password = wtforms.PasswordField('密码', validators=[DataRequired()])
    remeber_me = wtforms.BooleanField('一周内自动登录')
    submit = wtforms.SubmitField('登录')


class UserPasswordForm(FlaskForm):
    """修改密码表单"""
    old_password = wtforms.PasswordField('旧密码', validators=[DataRequired()], render_kw={'placeholder': '请输入旧密码'})
    new_password = wtforms.PasswordField('新密码',
                                         validators=[DataRequired(), EqualTo('new_password2', message='两次输入的密码不一致')],
                                         render_kw={'placeholder': '请输入新密码'})
    new_password2 = wtforms.PasswordField('确认新密码', validators=[DataRequired()], render_kw={'placeholder': '请确认新密码'})
    submit = wtforms.SubmitField('修改密码')
